import { Provider } from "react-redux";
import ReactDOM from "react-dom/client";
import Pages from "./pages/index.tsx";
import "./index.less";

import stores from "./models/index.ts";
import { showToast } from "./utils/index.ts";
import { initModels, initRequest } from "./utils/dva17/index";
import { KEY_TOKEN, SERVER_HOME } from "./config/index.ts";
import Mold from "./mold/index.tsx";

// 初始化数据管理
const APP_STORE = initModels(stores, false);
initRequest(SERVER_HOME, (status: any, data: any) => {
  console.log("status, data: ", status, data);
  if (status == 401) {
    const url = window.location.href;
    if (url.indexOf("#") == -1) return;
    showToast("登录过期，请重新登录", 1500);
    localStorage.removeItem(KEY_TOKEN);
    window.location.href = url.substring(0, url.indexOf("#"));
    return;
  }
  showToast(data, 1500);
});

// window设置
window.oncontextmenu = function () {
  //禁止右键
  return false;
};

ReactDOM.createRoot(document.getElementById("root")!).render(
  <Provider store={APP_STORE}>
    <Pages />
    <Mold />
  </Provider>
);
